#!/usr/bin/python

import sys

for eachLine in sys.stdin:
    eachLine = eachLine.strip()

    #Remove the number of categories an article has at end of record
    eachLine = "\t".join(eachLine.split("\t")[:len(eachLine.split("\t"))-2])

    art_name = eachLine.split("\t")[0]

    #This is to prune all junk categories
    if(art_name.find("Categor")!=-1):
        continue
    
    categories = eachLine.split("\t")[1:]

    #Emmit reverse categories,names pairs
    for eachCategory in categories:
        if(eachCategory != "Category"):
            print eachCategory+"\t"+art_name
